//
// Created by Zeppyrz on 2025/11/4.
//

#ifndef ZEDISK_SERVERTASK_H
#define ZEDISK_SERVERTASK_H

#include <functional>

#include "FileServerTask.h"
#include "Task.h"

// forward declaration
struct sockaddr;

namespace ZeDisk {

class ThreadPool;

/**
 * @brief ServerTask 服务段 仅接收连接回调
 */
class DECLSPEC ServerTask : public Task {
 public:
  ServerTask() = default;
  ~ServerTask() override = default;
  bool Init() override;
  bool Stop() override;

  void AcceptCallback(int, sockaddr *, int);

  // setter getter
  /**
   * @brief 读取或设置server_port
   *
   * @return server_port
   */
  [[nodiscard]] int &server_port() { return server_port_; }
  [[nodiscard]] ThreadPool *&Threadpool() { return threadpool_; }

 private:
  int server_port_ = -1;
  FileServerTask server_task_;
  ThreadPool *threadpool_ = nullptr;
};

}  // namespace ZeDisk

#endif  // ZEDISK_SERVERTASK_H
